package com.bupt.liutong.admin.core.action;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.bupt.liutong.admin.core.base.BaseAction;
import com.bupt.liutong.admin.core.bo.TreeBo;
import com.bupt.liutong.admin.core.exception.TreeDefNotFoundException;

public class TreeAction extends BaseAction {
	
	private TreeBo treeBo;
	
	public ActionForward dispCommonTree(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws TreeDefNotFoundException {
		request.setAttribute("treeForm", 
				treeBo.getCommonTree((String) request.getParameter("treeId")));
		request.setAttribute("treeNodeFormList", 
				treeBo.dispCommonTree((String) request.getParameter("treeId"), request.getSession().getAttribute("roleIds")));
		return mapping.findForward("dispCommonTreeSuccess");
	}
	
	public ActionForward dispCheckboxTree(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws TreeDefNotFoundException {
		request.setAttribute("treeForm", 
				treeBo.getCommonTree((String) request.getParameter("treeId")));
		request.setAttribute("treeNodeFormList", 
				treeBo.dispCommonTree((String) request.getParameter("treeId"), null));
		return mapping.findForward("dispCheckboxTreeSuccess");
	}
	
	public ActionForward dispModuleOperTree(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws TreeDefNotFoundException {
		request.setAttribute("treeForm", 
				treeBo.getCommonTree((String) request.getParameter("treeId")));
		request.setAttribute("treeNodeFormList", 
				treeBo.dispCommonTree((String) request.getParameter("treeId"), null));
		return mapping.findForward("dispModuleOperTreeSuccess");
	}

	public void setTreeBo(TreeBo treeBo) {
		this.treeBo = treeBo;
	}
}
